home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / scripts / createdb next >
Encoding:
Text File  |  1992-08-27  |  1.3 KB  |  82 lines

  1. #!/bin/sh
  2. # ----------------------------------------------------------------
  3. #   FILE
  4. #    createdb    create a postgres database
  5. #
  6. #   DESCRIPTION
  7. #    this program runs the monitor with the "-c" option to create
  8. #   the requested database.
  9. #
  10. #   IDENTIFICATION
  11. #     $Header: /private/postgres/src/scripts/RCS/createdb,v 1.4 1991/07/29 16:47:47 kemnitz Exp $
  12. # ----------------------------------------------------------------
  13.  
  14. #
  15. # find postgres tree
  16. #
  17.  
  18. if (test -n "$POSTGRESHOME")
  19. then
  20.     PG=$POSTGRESHOME
  21. else
  22.     PG=/usr/postgres
  23. fi
  24.  
  25. #
  26. # find monitor program
  27. #
  28.  
  29. if (test -f "$PG/bin/monitor")
  30. then
  31.     MONITOR=$PG/bin/monitor
  32. elif (test -f "MONITOR=$PG/obj*/support/monitor")
  33. then
  34.     MONITOR=$PG/obj*/support/monitor
  35. else
  36.     echo "$0: can't find the monitor program!"
  37.     exit 1
  38. fi
  39.  
  40. progname=$0
  41.  
  42. #
  43. # handle pgport and pghost
  44. #
  45.  
  46. if (test -n "$PGPORT")
  47. then
  48.     port=$PGPORT
  49. else
  50.     port=4321
  51. fi
  52.  
  53. if (test -n "$PGHOST")
  54. then
  55.     host=$PGHOST
  56. else
  57.     host=localhost
  58. fi
  59.  
  60. dbname=$USER
  61.  
  62. while (test -n "$1")
  63. do
  64.     case $1 in
  65.         -h) host=$2; shift;;
  66.         -p) port=$2; shift;;
  67.          *) dbname=$1;;
  68.     esac
  69.     shift;
  70. done
  71.  
  72. $MONITOR -TN -h $host -p $port -c "createdb $dbname" template1
  73.  
  74. if (test $? -ne 0)
  75. then
  76.     echo "$progname: database creation failed on $dbname."
  77.     exit 1
  78. fi
  79.  
  80. # successful execution
  81. exit 0
  82.